package org.ngbx.demo.flink.kafka.connector;


import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class KafkaMessageSchema implements DeserializationSchema<KafkaMessage> {
    final private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public KafkaMessage deserialize(byte[] message) throws IOException {
        // json 转成对象
        return objectMapper.readValue(message, KafkaMessage.class);
    }

    @Override
    public boolean isEndOfStream(KafkaMessage nextElement) {
        return false;
    }

    @Override
    public TypeInformation<KafkaMessage> getProducedType() {
        return TypeInformation.of(KafkaMessage.class);
    }
}
